//
//  UserAgreementVC.m
//  Cunli
//
//  Created by lilubin on 15/7/17.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "UserAgreementVC.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height


@interface UserAgreementVC () <UIWebViewDelegate>
{
    UIWebView *_webView;
}

@end

@implementation UserAgreementVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight-64)];
    [self.view addSubview:_webView];
    _webView.scalesPageToFit = YES;
    _webView.delegate = self;
    [self loadWebData];
    
    UIImageView *navBgImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
    [navBgImgView setImage:[UIImage imageNamed:@"NavigationBgImage"]];
    [self.view addSubview:navBgImgView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth/2-80, 22, 160, 40)];
    label.text = @"用户使用条款";
    [label setTextColor:[UIColor whiteColor]];
    label.textAlignment = NSTextAlignmentCenter;
    [navBgImgView addSubview:label];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(10, 27, 30, 30);
    [backBtn setImage:[UIImage imageNamed:@"regback01"] forState:UIControlStateNormal];
//    [backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    [self.view setBackgroundColor:[UIColor colorWithHexString:UIBgColorValue]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)backAction
{
    [self dismissViewControllerAnimated:YES completion:NULL];
    _webView = nil;
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:YES];
    if (_webView != nil) {
        _webView = nil;
    }
}

- (void)loadWebData
{
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"user_agreement" ofType:@"html"];
    NSString *htmlString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
    NSString *htmlStr = [NSString stringWithFormat:@"<html><body>%@</body></html>", htmlString];
    
    [_webView loadHTMLString:htmlStr baseURL:nil];
}

@end
